package com.joysuch.wwyt.bp.service.impl;

import com.joysuch.wwyt.bp.bean.vo.BpInvestigateConfigVo;
import com.joysuch.wwyt.bp.constant.InvestigateConfigNames;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigateConfig;
import com.joysuch.wwyt.bp.repository.BpInvestigateConfigDao;
import com.joysuch.wwyt.bp.service.BpInvestigateConfigService;
import com.joysuch.wwyt.common.constant.Constant;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class BpInvestigateConfigServiceImpl implements BpInvestigateConfigService {
    @Autowired
    BpInvestigateConfigDao configDao;

    @Override
    @Transactional
    public int editConfigByName(Long id, String status) {
        return configDao.updateById(id,status);
    }

    @Override
    public List<BpInvestigateConfigVo> findAll() {
        ArrayList<BpInvestigateConfigVo> result = new ArrayList<>();
        List<BpInvestigateConfig> configList = configDao.findAll();
        configList.forEach(each -> {
            BpInvestigateConfigVo configVo = new BpInvestigateConfigVo();
            BeanUtils.copyProperties(each,configVo);
            result.add(configVo);
        });
        return result;
    }

    @Override
    public String getStatusByName(String name) {
        return configDao.findStatusByName(name);
    }

}
